//
//  ShippingAddressCell.m
//  phmall
//
//  Created by admin on 2017/12/5.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "ShippingAddressCell.h"

@implementation ShippingAddressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    ShippingAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ShippingAddressCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        
        
        self.name=[[UILabel alloc]init];
        self.name.text=@"收货人:郑女士";
        self.name.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.name];
        
        self.phone=[[UILabel alloc]init];
        self.phone.text=@"18653145284";
        self.phone.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.phone];
        
        self.address=[[UILabel alloc]init];
        self.address.numberOfLines=2;
//        self.address.text=@"收货地址:福建省泉州市石狮市  灵秀镇  世贸国际  华闽写字楼15楼  滚石网络有限公司  1503";
        self.address.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.address.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.address];
        
        self.line=[[UIView alloc]init];
        self.line.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.line];
        
        self.defaultBut=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.defaultBut setTitle:Localized(@"默认地址") forState:UIControlStateNormal];
        self.defaultBut.titleLabel.font=[UIFont systemFontOfSize:13];
        [self.defaultBut setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        [self.defaultBut setImage:[UIImage imageNamed:@"勾选"] forState:UIControlStateSelected];
        [self.defaultBut setTitleColor:[UIColor colorWithHexString:@"#adadad"] forState:UIControlStateNormal];
        [self.defaultBut setImage:[UIImage imageNamed:@"未勾选"] forState:UIControlStateNormal];
        [self.defaultBut layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        [self.defaultBut addTarget:self action:@selector(editDefault) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.defaultBut];
        
        self.removeBut=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.removeBut setTitle:Localized(@"删除地址") forState:UIControlStateNormal];
        self.removeBut.titleLabel.font=[UIFont systemFontOfSize:13];
        [self.removeBut setTitleColor:[UIColor colorWithHexString:@"#adadad"] forState:UIControlStateNormal];
        [self.removeBut setImage:[UIImage imageNamed:@"垃圾箱"] forState:UIControlStateNormal];
        [self.removeBut layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        [self.removeBut addTarget:self action:@selector(removeAddress) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.removeBut];
        
    }
    return self;
}
-(void)editDefault{
    if (self.delegate && [self.delegate respondsToSelector:@selector(editDefault:)]) {
        [self.delegate editDefault:self];
    }
}
-(void)removeAddress{
    if (self.delegate && [self.delegate respondsToSelector:@selector(removeAddress:)]) {
        [self.delegate removeAddress:self];
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
    }];
    
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.top.offset(10);
    }];
    
    [self.address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.right.offset(-10);
        make.top.equalTo(self.name.mas_bottom).offset(10);
//        make.bottom.equalTo(self.line.mas_top).offset(-10);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(1);
        make.bottom.equalTo(self.defaultBut.mas_top).offset(-10);
    }];
    
    [self.defaultBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.bottom.offset(-10);
        
    }];
    
    [self.removeBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.bottom.offset(-10);
    }];
}
-(void)setModel:(AddressModel *)model{
    self.name.text=[NSString stringWithFormat:@"%@:%@",Localized(@"收货人"),model.consignee];
    self.address.text=[NSString stringWithFormat:@"%@:%@  %@  %@  %@",Localized(@"收货地址"),model.province,model.city,model.county,model.address];
    self.phone.text=model.mobile;
    self.defaultBut.selected=model.is_buy;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
